package com.rongshu.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;

/**
 * 为解决OnScrollChangeListener只能在API23版本以上使用
 */
public class YNestedScrollView extends NestedScrollView {

    private OnScrollChangeListener mOnScrollChangeListener;

    public YNestedScrollView(@NonNull Context context) {
        super(context);
    }

    public YNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public YNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (mOnScrollChangeListener != null) {
            mOnScrollChangeListener.onScrollChange(this, l, t, oldl, oldt);
        }
    }

    /**
     * 接口
     */
    public interface OnScrollChangeListener {
        void onScrollChange(YNestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY);
    }

    public void setOnScrollChangeListener(OnScrollChangeListener listener) {
        mOnScrollChangeListener = listener;
    }
}
